package cn.zhangtiancinb.simple_demo.http.controller;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Dubbo访问控制器
 *
 * @author 张天赐
 */
@RestController
@RequestMapping("/dubbo")
public class DubboController {

    @Value("${dubbo_consumer_http_default}")
    String defaultUrl;
    @Value("${dubbo_consumer_http_alwaysOk}")
    String alwaysOkUrl;

    /**
     * 默认实现
     *
     * @param value 用于判断是否出错的参数
     * @return 函数结果
     */
    @ResponseBody
    @RequestMapping(value = "default")
    public String auto(@RequestParam(required = false, defaultValue = "0") Integer value) {
        return HttpUtil.get(StrUtil.format("{}?value={}", defaultUrl, value));
    }

    /**
     * 状态码总是200
     *
     * @param value 用于判断是否出错的参数
     * @return 函数结果
     */
    @ResponseBody
    @RequestMapping(value = "always200")
    public String alwaysOk(@RequestParam(required = false, defaultValue = "0") Integer value) {
        return HttpUtil.get(StrUtil.format("{}?value={}", alwaysOkUrl, value));
    }
}
